package dp.leetcode_122;

public class GreedSolution {
    public int maxProfit(int[] prices) {
        int maxProfit = 0;
        for (int i = 1; i < prices.length; i++) {
//            使用 Math 会增加运算次数
//            maxProfit += Math.max(0, prices[i] - prices[i - 1]);
            int temp = prices[i] - prices[i - 1];
            if (temp > 0) {
                maxProfit += temp;
            }
        }
        return maxProfit;
    }
}
